package com.atguigu.tingshu.album.api;

import cn.hutool.json.JSONObject;
import com.atguigu.tingshu.album.mapper.BaseAttributeMapper;
import com.atguigu.tingshu.album.service.BaseAttributeService;
import com.atguigu.tingshu.album.service.BaseCategoryService;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.album.BaseAttribute;
import com.atguigu.tingshu.model.album.BaseCategory1;
import com.atguigu.tingshu.model.album.BaseCategory3;
import com.atguigu.tingshu.model.album.BaseCategoryView;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@Tag(name = "分类管理")
@RestController
@RequestMapping(value="/api/album")
@SuppressWarnings({"all"})
public class BaseCategoryApiController {

	@Autowired
	private BaseCategoryService baseCategoryService;

	@Autowired
	private BaseAttributeService baseAttributeService;


	/**
	 * 查询所有分类
	 * @return
	 */
	@Operation(tags = "查询所有分类")
	@GetMapping("/category/getBaseCategoryList")
	public Result<List<JSONObject>> getBaseCategorylist(){
		List<JSONObject> list = baseCategoryService.getBaseCategorylist();
		return Result.ok(list);
	}

	// /api/album/category/findAllCategory1
	@GetMapping("/category/findAttribute/{categoryId}")
	public Result<List<BaseAttribute>> getAttributesByCategory1Id(@PathVariable("categoryId") Long categoryId){
		List<BaseAttribute> list =  baseAttributeService.getAttributesByCategory1Id(categoryId);
		return Result.ok(list);
	}

	@GetMapping("/category/getCategoryView/{category3Id}")
	public Result<BaseCategoryView> getCategoryView(@PathVariable Long category3Id){
		BaseCategoryView baseCategoryView = baseCategoryService.getCategoryView(category3Id);
		return Result.ok(baseCategoryView);
	}

	@GetMapping("/category/findTopBaseCategory3/{category1Id}")
	public Result<List<BaseCategory3>> getTop7BaseCategory3(@PathVariable Long category1Id){
		List<BaseCategory3> list = baseCategoryService.getTop7BaseCategory3(category1Id);
		return Result.ok(list);
	}

	@GetMapping("/category/getBaseCategoryList/{category1Id}")
	public Result<JSONObject> getBaseCategoryListByCategory1Id(@PathVariable Long category1Id){
		JSONObject jsonObject = baseCategoryService.getBaseCategoryListByCategory1Id(category1Id);
		return Result.ok(jsonObject);
	}

	/**
	 * 查询所有一级分类列表
	 * @return
	 */
	@GetMapping("/category/findAllCategory1")
	public Result<List<BaseCategory1>> getAllCategory1() {
		return Result.ok(baseCategoryService.list());
	}
}

